package com.ctbri.io;

import java.io.File;
import java.util.Arrays;

public class Ex2_SortedDirList {

	private String path;
	
	public Ex2_SortedDirList(String path) {
		this.path = path;
	}
	
	public String[] list() {
		String[] results = new File(path).list();
		Arrays.sort(results);
		return results;
	}
	
	public String[] list(String regex) {
		String[] results = new File(path).list((d, n) -> {
			return n.matches(regex);
		});
		Arrays.sort(results);
		return results;
	}
	
	public static void main(String[] args) {
		Ex2_SortedDirList dirList = new Ex2_SortedDirList("D:/Java/workspace/thinkinginjava/src/com/ctbri/util");
		System.out.println(Arrays.toString(dirList.list()));
		System.out.println(Arrays.toString(dirList.list("Pair.java")));
	}
}
